package com.ruoyi.security.service.backtest.gridtrading.processor;

import com.ruoyi.security.enums.SecurityTradeTypeEnum;
import com.ruoyi.security.service.backtest.gridtrading.context.BacktestContext;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author yeoman
 * @date 2025/11/8 01:23
 * @description
 */
@Component
public class TradeProcessorServiceFactory {

    @Resource
    @Qualifier("buyTradeProcessor")
    private ITradeProcessorService buyTradeProcessor;

    @Resource
    @Qualifier("sellTradeProcessor")
    private ITradeProcessorService sellTradeProcessor;

    public ITradeProcessorService getTradeProcessorService(BacktestContext context) {
        if (context.getBacktestVariable().getTradeInfo().getTradeType().equals(SecurityTradeTypeEnum.BUY.getKey())) {
            return buyTradeProcessor;
        } else if (context.getBacktestVariable().getTradeInfo().getTradeType().equals(SecurityTradeTypeEnum.SELL.getKey())) {
            return sellTradeProcessor;
        }
        throw new IllegalArgumentException("不支持的交易类型: " + context.getBacktestVariable().getTradeInfo().getTradeType());
    }

}
